//var menuTree;
var prefix = basepath + "/employee"


$(function() {
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {

		addEmployee();
	}
});

function closeThis(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}


/*文件上传*/
function doUpload(target) {
	/*校验文件大小*/
	var fileSize = 0;
	if (!target.files) {
		var filePath = target.value;
		var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
		var file = fileSystem.GetFile(filePath);
		fileSize = file.Size;
	} else {
		fileSize = target.files[0].size;
	}
	var size = fileSize / 1024;
	if (size > 5000) {
		page_alert("上传文件不能大于5M");
		target.value = "";
		return false;
	}
	/*上传文件*/
	var formData = new FormData($("#batchRechargePointForm")[0]);
	$.ajax({
		url : basepath + "file/uploadRecharePointFile",
		type : 'POST',
		data : formData,
		async : false,
		cache : false,
		contentType : false,
		processData : false,
		success : function(returndata) {
			if (returndata) {
				$("#filePath").val(returndata);
			} else {
				page_alert("上传文件失败");
			}
		},
		error : function(returndata) {
			page_alert("上传文件失败");
		}
	});
}


function addEmployee() {
	var role = $('#signupForm').serialize();
	console.log('role:' + JSON.stringify(role) )
	$.ajax({
		cache : true,
		type : "POST",
		url : prefix + "/addEmployeeInfo",
		data : role, // 你的formid

		async : false,
		error : function(request) {
			alert("Connection error:" + JSON.stringify(request));
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
//				sleep(3000);
//				parent.reload();
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);

			} else {
				parent.layer.msg(data.msg);
			}
		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			empName : {
				required : true
			}
			,certNo : {
				required : true
			}
			,bankCardNbr : {
				required : true,
				minlength: 16
			}
			,mobile : {
				required : false,
				minlength: 11
			}
		},
		messages : {
			empName : {
				required : icon + "请输入姓名"
			}
			,certNo : {
				required :  icon + "请输入身份证号"
			}
			,bankCardNbr : {
				required :  icon + "请输入福利卡号"
			}
			,mobile : {
				minlength : icon + "请输入11位手机号"
			}
		}
	});
}

/**刷新权限列表 */
function reLoadList(){
    var managerType=$("#managerType").val();
    var instanceId=$("#instanceId").val();
    if(managerType==3){
        $.ajax({
           type:"post",
		   url:"../adminLoginJson/reLoadList.action",
		   data:{"instanceId":instanceId}, 
		   async : false, 
		   success:function(data){
		     var result = eval("(" + data + ")");	     
		     if(result.style==1){
		        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		     }else if(result.style==2){
		        $.fn.zTree.init($("#treeDemo"), setting, zNodesCom);
		     }else{
		        $("#error").show();
			    $("#error").text("系统异常！");
		     }
		  },
		  error:function(){
			$("#error").show();
			$("#error").text("系统错误！");
		  }	    
      }); 
    }
}

